﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminSite.Master" AutoEventWireup="true"
    CodeBehind="ArticleListPage.aspx.cs" Inherits="phudieuhungthinh.Admin.ArticleListPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="/Styles/control-style.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/vm/handler.js" type="text/javascript"></script>
    <style type="text/css">
        .btn-add
        {
            background-color: #ccc;
            color: black;
            font-family: 'Oswald';
            font-size: 20px;
            text-decoration: none;
            cursor: pointer;
            border: none;
        }
    </style>
    <script type="text/javascript">

        var dataHandler = new handler(location.pathname);
        function addClick() {
            window.location.href = 'ArticleItem.aspx';
        }
        function deleteClick(id) {
            var answer = confirm("Are you sure delete this article?");
            if (answer) {
                if (dataHandler.article.remove(id))
                    window.location.href = location.pathname;
                else
                    alert("failed");
            }
        }
        $(document).ready(function () {
            // Prepare jtable plugin
            $('#container').jtable({
                title: 'Tin tức (Articles)',
                paging: true, //Enables paging
                pageSize: 8, //Actually this is not needed since default value is 10.
                sorting: true, //Enables sorting
                defaultSorting: 'Title ASC', //Optional. Default sorting on first load.
                actions: {
                    listAction: location.pathname + '/GetAll'
                },
                fields: {
                    ID: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Title: {
                        title: 'Tiêu đề',
                        width: '30%'
                    },
//                    ArticleSapo: {
//                        title: 'Mô tả',
//                        width: '40%'
//                    },
                    CustomActionEdit: {
                        title: 'Edit',
                        list: true,
                        sorting: false,
                        edit: false,
                        display: function (data) {
                            if (data.record) {
                                return '<a href="ArticleItem.aspx?id=' + data.record.ID + '">Edit</a>';
                            }
                            return null;
                        }
                    },
                    CustomActionDelete: {
                        title: 'Remove',
                        list: true,
                        sorting: false,
                        edit: false,
                        display: function (data) {
                            if (data.record) {
                                return "<a href='javascript:void(0)' onclick=\"deleteClick('" + data.record.ID + "');\">Remove</a>";
                            }
                            return null;
                        }
                    }
                }
            });
            //Load category list from server
            $('#container').jtable('load');
        }); 
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="button add">
        <a href="javascript:void(0)" onclick="addClick()">Thêm tin (Add article)</a>
    </div>
    <div class="clear">
    </div>
    <div id="container">
    </div>
</asp:Content>
